home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: sequence pts wrt pointer dereferencing
- Date: Sat, 06 Jan 96 13:20:41 GMT
- Organization: none
- Message-ID: <820934441snz@genesis.demon.co.uk>
- References: <optimal.8.7116A605@vir.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <optimal.8.7116A605@vir.com> optimal@vir.com "optimal" writes:
-
- >For reasons of virtual memory swapping, we have what amounts to the following:
- >
- >int* A (int i)
- > {
- > static int x;
- >
- > x = i;
- > return &x;
- > }
- >
- >foo ( )
- > {
- > .....
- > *A(1) += *A(100);
- > }
-
- This doesn't make much sense. What exactly are you trying to buy yourself
- in a 'virtual memory swapping' environment by doing this? I assume this code
- isn't run at an ordinary 'user' level since virtual memory is transparent
- to such code. If you're expecting object addresses to change under your feet
- then I doubt whether any C code will last very long.
-
- >This fails due to the value *A(100) not being stored before the *A(1) is
- >evaulated. The following works:
- >
- > int tmp = *A(100);
- > *A(1) += tmp;
-
- This seems to be a very long-winded way of storing 101 in a static variable.
- Explain why this could result in different behaviour to:
-
- A(1+100);
-
- >Is there another alternative to the use of tmp variables?
-
- Possibly, but you need to state your constraints. For instance the following
- may be what you are looking for, but then possibly not.
-
- int* A1 (int i)
- {
- static int x;
-
- x = i;
- return &x;
- }
-
- int* A2 (int i)
- {
- static int x;
-
- x = i;
- return &x;
- }
-
- foo ( )
- {
- .....
- *A1(1) += *A2(100);
- }
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-